#include "Time.h"
Time::Time(int h, int m)
{
	hour = h;
	minute = m;
	if(h < 0 || h > 23)
	{
		h = 0;
	}
	if(m < 0 || m >= 60)
	{
		m = 0;	
	}
}
Time Time::operator + (const Time& y) const
{
	int hx = this->hour;
	int hy = y.getHour();
	int mx = this->minute;
	int my = y.getMinute();
	
	int m = ((hx + hy)*60 + mx + my) % 60;
	int h = ((hx + hy)*60 + mx + my) / 60;
	return Time(h,m);
}
Time Time::operator + (int n) const
{
    int hx = this->hour;
    int hy = n / 60;
    int mx = this->minute;
    int my = n % 60;

    int m = ((hx + hy)*60 + mx + my) % 60;
    int h = ((hx + hy)*60 + mx + my) / 60;
    return Time(h, m);
}

int Time::operator - (const Time& y) const
{
    int hx = this->hour;
    int hy = y.getHour();
    int mx = this->minute;
    int my = y.getMinute();

    return (hx-hy)*60+mx-my;
}

inline int hour(const Time& t) 
{
	return t.getHour();
}

inline int minute(const Time& t)
{
	return t.getMinute();
}

ostream&
operator << (ostream& os, const Time& x)
{
	string right;
	if(minute(x)<10)
	{
		right = "0" + to_string(minute(x));
	}else{
	    right = to_string(minute(x));
	}
    return os <<hour(x)<<':'<<right;
}
